<?php

namespace App\Http\Controllers;

use App\Models\Blog;
use App\Models\User;
use Illuminate\Http\Request;
use Auth;

class BlogsController extends Controller
{
    public function __construct()
    {
        $this->middleware('auth');
    }
    public function store(Request $request)
    {
        $this->validate($request,[
            'content' => 'required|max:255',
        ]);
        Auth::user()->blogs()->create([
            //'user_id' => Auth::user()->id,
            'content' => $request['content'],
        ]);

        session()->flash('success','创建成功！');
        return back();
    }

    public function destroy(Blog $blog)
    {
        $this->authorize('destroy',$blog);
        $blog->delete();
        session()->flash('success','删除成功！');
        return back();
    }
}
